package threeD.Csg;

import twoD.Csg.Primitive;
import inf.jlinalg.IVector;

public class Cylinder extends Primitive {

	private double cx, cy, cz, r, h;

	/**
	 * create a cylinder with axis parallel to z with center at (ox,oy,oz)
	 * 
	 * @param ox
	 * @param oy
	 * @param oz
	 * @param r
	 * @param h
	 */
	public Cylinder(double ox, double oy, double oz, double r, double h) {
		this.cx = ox;
		this.cy = oy;
		this.cz = oz;
		this.r = r;
		this.h = h;
	}

	@Override
	public boolean contain(double... p) {
		IVector phat = getInverseLocation(p);
		return (((Math.pow(phat.get(0) - cx, 2) + Math.pow(phat.get(1) - cy, 2)) - Math
				.pow(r, 2)) <= TOL)
				&& (phat.get(2) >= cz - TOL && phat.get(2) - cz <= h + TOL);
	}
}
